package luccy.util;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

import luccy.exception.IllegalAccessRuntimeException;
import luccy.exception.InstantiationRuntimeException;
import luccy.exception.InvocationTargetRuntimeException;
import luccy.exception.LIllegalArgumentRuntimeException;
import luccy.exception.LuccyRuntimeException;

public abstract class ConstructorUtil {

	public static <T> T newInstance(Constructor<T> c, Object... args) throws LuccyRuntimeException {
				try {
					return c.newInstance(args);
				} catch (IllegalArgumentException e) {
					throw new LIllegalArgumentRuntimeException(e, ConstructorUtil.class, args);
				} catch (InstantiationException e) {
					throw new InstantiationRuntimeException(c.getDeclaringClass(), e);
				} catch (IllegalAccessException e) {
					throw new IllegalAccessRuntimeException(c.getDeclaringClass(), e);
				} catch (InvocationTargetException e) {
					throw new InvocationTargetRuntimeException(c.getDeclaringClass(), e);
				}
	}

}
